      SUBROUTINE COILDP(XMB)
C
      IMPLICIT REAL*8(A-H,O-Z)
C
      COMMON/MAGCOM/COILS(3)
C
      COMMON/MOMENT/IDUM(3),IMGMTS,JDUM(2)
C
      COMMON/OUTTHR/SMAGB(3),XMB1(3),RWH(3)
C
      DIMENSION XMB(3)
C
      DATA IFLAG/0/
C
      B1=SMAGB(1)
      B2=SMAGB(2)
      B3=SMAGB(3)
      B12=B1*B1+B2*B2
      B12=DSQRT(B12)
      IF(B12.LT.DABS(B3)) GO TO 99
      IF(IMGMTS.GT.2) GO TO 10
C
C     PROPORTIONAL DRIVE
C
      C1=B2*COILS(1)/B12
      C2=B1*COILS(2)/B12
      GO TO 20
   10 CONTINUE
C
C     CONSTANT LEVEL DRIVE
C
      C1=0.0D0
      IF(B2.NE.0.0D0) C1=B2*COILS(1)/DABS(B2)
      C2=0.0D0
      IF(B1.NE.0.0D0) C2=B1*COILS(2)/DABS(B1)
   20 CONTINUE
      XMB(1)=B3*C2
      XMB(2)=-B3*C1
      XMB(3)=B2*C1-B1*C2
      GO TO 100
C
   99 CONTINUE
      IF(IFLAG.EQ.0) WRITE(6,600) B1,B2,B3
  600 FORMAT(' ',5X,'BODY FRAME MAG FIELD COMPONENTS',1P3E13.5,
     1 ' SPIN AXIS COMPONENT GREATER THAN TRANSVERSE COMPONENT')
      IFLAG=1
  100 CONTINUE
C
C
C
      RETURN
C
      END
